<?php
/**
 * Author: Traveler
 * Time  : 2021/12/25 0025 15:56
 */

namespace app\validate;

use app\ErrorCode;
use think\Validate;

class StaffValidate extends Validate
{
    /**
     * 验证规则
     *
     * @var string[]
     */
    protected $rule = [
        'name'          => 'require|max:16',
        'cellphone'     => 'require|mobile|unique:\\app\\model\\StaffModel', // 传入模型，为了兼容软删除
        'gender'        => 'require|in:0,1',
        'email'         => 'require|email|unique:\\app\\model\\StaffModel',
        'department_id' => 'require|integer|gt:0',
        'role_id'       => 'require|integer|gt:0',
        'status'        => 'require|in:0,1',
    ];

    /**
     * 提示信息
     *
     * @var string[]
     */
    protected $message = [
        'name.require'          => ErrorCode::REQUIRE_STAFF_NAME,
        'name.max'              => ErrorCode::INVALID_STAFF_NAME_LEN,
        'cellphone.require'     => ErrorCode::REQUIRE_CELLPHONE,
        'cellphone.mobile'      => ErrorCode::INVALID_CELLPHONE,
        'cellphone.unique'      => ErrorCode::DUPLICATE_CELLPHONE,
        'gender.require'        => ErrorCode::REQUIRE_GENDER,
        'gender.in'             => ErrorCode::INVALID_GENDER,
        'email.require'         => ErrorCode::REQUIRE_STAFF_EMAIL,
        'email.email'           => ErrorCode::INVALID_STAFF_EMAIL,
        'email.unique'          => ErrorCode::DUPLICATE_STAFF_EMAIL,
        'department_id.require' => ErrorCode::REQUIRE_DEPARTMENT_ID,
        'department_id.integer' => ErrorCode::INVALID_DEPARTMENT_ID,
        'department_id.gt'      => ErrorCode::INVALID_DEPARTMENT_ID,
        'role_id.require'       => ErrorCode::REQUIRE_ROLE_ID,
        'role_id.integer'       => ErrorCode::INVALID_ROLE_ID,
        'role_id.gt'            => ErrorCode::INVALID_ROLE_ID,
        'status.require'        => ErrorCode::REQUIRE_STAFF_STATUS,
        'status.in'             => ErrorCode::INVALID_STAFF_STATUS,
    ];
}